<template>
  <div class="solidBarView" id="solidBarView"></div>
</template>
<script>
import { wasteTypeSumRank6 } from "../utils/api";
import * as echarts from "echarts";
export default {
  props: {
    timeValue: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      echartsPie: null,
      companyId: "",
    };
  },
  watch: {
    timeValue() {
      this.getData();
    },
  },
  created() {
    let userData = JSON.parse(localStorage.getItem("useroBJ"));
    this.companyId = userData.companyId;
  },
  mounted() {
    this.getData();
  },
  methods: {
    async getData() {
      const { data } = await wasteTypeSumRank6(
        this.companyId,
        this.timeValue,
        "entDetails"
      );
      if (data.success) {
        let chatData = data.data;
        let sum = [];
        let dateTime = [];
        chatData.forEach((item) => {
          sum.push(item.sum);
          dateTime.push(item.code);
        });
        this.$nextTick(() => {
          this.initChart(dateTime, sum);
        });
      }
    },
    initChart(dateTime, sum) {
      this.echartsPie = echarts.init(document.getElementById("solidBarView"));
      this.echartsPie.setOption({
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        legend: {
          icon: "circle",
          left: "right",
          textStyle: {
            fontSize: 17,
          },
        },
        xAxis: {
          type: "category",
          data: dateTime,
        },
        yAxis: {
          type: "value",
        },
        grid: {
          left: 10,
          right: 4,
          bottom: 8,
          top: 10,
          containLabel: true,
        },
        series: [
          {
            type: "bar",
            data: sum,
            itemStyle: {
              color: "#6C64CE",
            },
          },
        ],
      });
    },
  },
};
</script>
<style lang="less">
.solidBarView {
  width: 100%;
  height: 160px;
}
</style>
